#include <gtest/gtest.h>
#include <thread>
#include "scheduler/sequence_scheduler.h"
#include "scheduler/scheduler_factory.h"
#include "../sample/navigation_task.h"
#include "../sample/battery_level_check.h"

TEST(test_sequence_scheduler_demo, test_sequence_scheduler)
{
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");
    auto battery_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");

    auto sequence_scheduler = scheduler::SchedulerFactory<scheduler::SequenceScheduler>::createScheduler("navigation_scheduler");

    sequence_scheduler->appendTask(battery_check);
    sequence_scheduler->appendTask(navigation_task);


//    std::thread([&sequenceScheduler]
//                {
//                    usleep(9000);
//                    EASE_INFO("pause...");
//                    sequenceScheduler->pause();
//                    sleep(10);
//                    EASE_INFO("resume...");
//                    sequenceScheduler->resume();
//                }).detach();

    sequence_scheduler->run();

    EASE_INFO("done");
}

TEST(test_sequence_scheduler_demo_pause, test_sequence_scheduler)
{
    auto battery_level_check_task = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check_task");
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");

    auto sequenceScheduler = scheduler::SchedulerFactory<scheduler::SequenceScheduler>::createScheduler("navigation_scheduler");
    sequenceScheduler->appendTask(battery_level_check_task);
    sequenceScheduler->appendTask(navigation_task);

    std::thread([&sequenceScheduler]
                {
                    sleep(1);
                    EASE_INFO("pause...");
                    sequenceScheduler->pause();
                    sleep(10);
                    EASE_INFO("resume...");
                    sequenceScheduler->resume();
                }).detach();

    sequenceScheduler->run();

    EASE_INFO("done");
}
